﻿

@{
    Layout = "";
}
<style>
    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 25% !important;
    }
</style>
<div ng-controller="BuildingListController">
    <h3>楼层管理</h3>

    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
        <div class="panel-heading">
            <div class="form-inline ng-pristine ng-valid">
                <div class="form-group">
                    <input id="input-email" placeholder="楼号" class="form-control" type="text" ng-model="Keywords">
                    
                    <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()" ng-model="Keywords">
                        <span class="btn-label">
                            <em class="fa fa-search"></em>
                        </span>搜索
                    </button>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-labeled btn-success" ng-click="BuildingAdd(0)" ng-show="UserInfo.IsAdd || UserInfo.IsAdmin">
                        <span class="btn-label">
                            <em class="fa fa-plus"></em>
                        </span>新增
                    </button>
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-labeled btn-success" ng-click="godt()">
                        <span class="btn-label">
                            <em class="fa fa-plus"></em>
                        </span>导出报表
                    </button>
                </div>
            </div>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                    <tbody>
                        <tr ng-repeat="item in $data" ng-show="UserInfo.IsQuery || UserInfo.IsAdmin">
                            
                            <td data-title="'楼号'" class="text-center">{{item.BuildingNO}}</td>
                            <td data-title="'地理位置'" class="text-center">{{item.Address}}</td>
                            <td data-title="'操作'" nowrap="nowrap" class="text-center">
                                @*<button type="button" ng-click="BuildingLocation(item.BuildingNO)" class="btn btn-sm btn-info" title="位置">
                                    <em class="fa fa-location-arrow"></em>
                                </button>*@
                                <button type="button" ng-click="BuildingEdit(item.Id)" class="btn btn-sm btn-edit" title="编辑" ng-show="UserInfo.IsEdit ||UserInfo.IsAdmin">
                                    <em class="fa fa-edit"></em>
                                </button>
                                <button type="button" ng-click="BuildingDel($index, item.Id)" class="btn btn-sm btn-danger" title="删除" ng-show="UserInfo.IsDel || UserInfo.IsAdmin">
                                    <em class="fa fa-trash"></em>
                                </button>
                               
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/ng-template" id="deleteConfirmDialog">
    <div class="ngdialog-message text-center">
        <h3>确定要删除吗?</h3>
        <button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
        <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>
    </div>
</script>

<script>
    App.controller('BuildingListController', [
    '$scope', '$resource', '$state', '$route', '$http', 'ngTableParams', 'ngTableDataService', 'Notify', '$filter', 'ngDialog', "$stateParams", "$timeout", "toaster",
        function ($scope, $resource, $state, $route, $http, ngTableParams, ngTableDataService, Notify, $filter, ngDialog, $stateParams, $timeout, toaster) {
            'use strict';
            //楼层单元
            $scope.isLoading = true;
            //数据查询
            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    BuildingNO : 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                        Keywords: $scope.Keywords,
                        UnitLevel: $scope.UnitLevel
                    };
                    $http.post('/Building/GetBuildingList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            
                            params.total(data.Total);
                            $defer.resolve(data.Results);
                            $scope.UserInfo = data._UserInfo;
                            $scope.isLoading = false;
                        });
                }
            });
            
            $scope.godt = function () {
               
                var keyword = "";
                if ($scope.Keywords != undefined)
                {
                    keyword = $scope.Keywords;
                }

                location.href = "/Report/GetMemberList?Keywords=" + keyword + "&UnitLevel=" + $scope.UnitLevel;
            }
                        
            //跳转新增页面
            $scope.BuildingAdd = function () {
                $state.go('app.buildingdetail', { "id": 0 });
            }

            //跳转地理位置页面
            $scope.BuildingLocation = function (id) {
                $state.go('app.BuildingLocation', { "id": id });
            }
            //跳转编辑页面
            $scope.BuildingEdit = function (id) {
                alert(id)
                $state.go('app.buildingdetail', { "id": id });
            }

            //删除大楼
            $scope.BuildingDel = function (index,id) {
                ngDialog.openConfirm({
                    template: 'deleteConfirmDialog',
                    className: 'ngdialog-theme-default'
                }).then(function (value) {
                    $scope.isLoading = true;
                    $http.post("/Building/BuildingDel", { BuildingNO: id }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            $scope.tableParams.data.splice(index, 1);
                            Notify.alert('操作成功!', { status: 'success' });
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                        }
                        $scope.isLoading = false;
                    });
                }, function (reason) {
                }
                );
            }
        }
    ]);
</script>
